package org.sample.dataconsumer.client;

import org.sample.dataconsumer.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import feign.hystrix.FallbackFactory;

@Component
public class UserFeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {

	private static final Logger LOGGER = LoggerFactory.getLogger(UserFeignClientFallbackFactory.class);

	@Override
	public UserFeignClient create(Throwable cause) {
		return new UserFeignClient() {

			@Override
			public User getUser(String id) {

				LOGGER.error("Get user failed and falled back", cause);

				User user = new User();
				user.setId(-1L);
				user.setUserName("Default");

				return user;
			}
		};
	}

}
